package com.wenjie.original.entity;

import com.mybatisflex.annotation.EnumValue;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import com.mybatisflex.core.keygen.KeyGenerators;
import com.wenjie.common.enumHandler.IEnum;
import com.wenjie.original.entity.common.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Arrays;

@Data
@Table("sys_log_oper")
@ApiModel("操作日志记录表 ")
public class SysLogOper extends BaseEntity {

    @Id(keyType = KeyType.Generator, value = KeyGenerators.snowFlakeId)
    @ApiModelProperty("日志主键")
    private Long sysLogOperId;

    @ApiModelProperty("操作模块")
    private String title;

    @ApiModelProperty("方法名")
    private String method;

    @ApiModelProperty("操作人员的id")
    private Long sysAdminId;

    @ApiModelProperty("请求url")
    private String operUrl;

    @ApiModelProperty("请求参数")
    private String operParam;

    @ApiModelProperty("返回参数")
    private String jsonResult;

    @ApiModelProperty("操作状态（0成功 1失败 2未知）")
    private STATUS status;

    @ApiModelProperty("消耗时间")
    private Long costTime;

    @Getter
    @AllArgsConstructor
    public enum BUSINESS_TYPE implements IEnum<Integer> {
        arg0(0, "其他"), arg1(1, "新增"), arg2(2, "修改"), arg3(3, "删除");

        @EnumValue
        private Integer code;
        private String message;

        /**
         * @Description 通过code进行查询枚举值
         * @author wenjie
         * @date 2024/5/30 15:21
         */
        public static BUSINESS_TYPE getBycode(Integer code) {
            return Arrays.stream(BUSINESS_TYPE.values()).filter(s -> s.getCode().equals(code)).findFirst().orElse(null);
        }


    }

    @Getter
    @AllArgsConstructor
    public enum OPERATOR_TYPE implements IEnum<Integer> {
        arg0(0, "其他"), arg1(1, "后台用户"), arg2(2, "手机端用户");

        @EnumValue
        private Integer code;
        private String message;

        /**
         * @Description 通过code进行查询枚举值
         * @author wenjie
         * @date 2024/5/30 15:21
         */
        public static OPERATOR_TYPE getBycode(Integer code) {
            return Arrays.stream(OPERATOR_TYPE.values()).filter(s -> s.getCode().equals(code)).findFirst().orElse(null);
        }
    }

    @Getter
    @AllArgsConstructor
    public enum STATUS implements IEnum<Integer> {
        arg0(0, "成功"), arg1(1, "失败"), arg2(2, "未知");

        @EnumValue
        private Integer code;
        private String message;

        /**
         * @Description 通过code进行查询枚举值
         * @author wenjie
         * @date 2024/5/30 15:21
         */
        public static STATUS getBycode(Integer code) {
            return Arrays.stream(STATUS.values()).filter(s -> s.getCode().equals(code)).findFirst().orElse(null);
        }
    }

}
